// pages/Type/Type.js 
Page({
  data: {
    currentIndex: 0,
    // 评论数量 
    remark: 0,
    //点赞数量 
    lovenum: 0,
    //浏览数量 
    though: 0,
    //内容评论样式 
    top_comments_content: "",
    //菜单类型 
    navType: 'image',
    // 页码
    page: 0,
    //菜单导航数组 
    TypeNavMenuList: [{
        id: 1,
        item: "图片",
        type: "image"
      },
      {
        id: 2,
        item: "动图",
        type: "gif"
      },
      {
        id: 3,
        item: "小视频",
        type: "video"
      },
      {
        id: 4,
        item: "笑话",
        type: "text"
      }, {
        id: 5,
        item: "其他",
        type: "other"
      }
    ],
    //轮播图数组 
    ImageList: [{
        url: "../../Images/swiper/BasicsBg.png"
      },
      {
        url: "../../Images/swiper/componentBg.png"
      },
      {
        url: "../../Images/swiper/share.jpg"
      },
      {
        url: "../../Images/swiper/zanCode.jpg"
      }
    ],
    // 内容列表 
    contentList: []
  },
  // 选中菜单改变的菜单样式 
  ChangeNav: function(e) {
    // let that = this 
    this.setData({
      currentIndex: e.currentTarget.id,
      //获取选中的菜单类型 
      navType: e.currentTarget.dataset.type
    })
    var type = this.data.navType
    var pagenum=this.data.page
    this.MyshowLoading(pagenum,type)
    console.log(type)
  },
  // 获取子组件传过来的值 
  handleClick: function(e) {
    const {
      index
    } = e.detail;
    console.log(index)
  },
  // 计算点赞数量 
  Countlovenum: function() {
    var num = this.data.lovenum
    this.setData({
      lovenum: num + 1
    })
  },
  // 计算浏览人数 
  Countthoughnum: function() {
    var num = this.data.though
    this.setData({
      though: num + 1
    })
  },
  //计算页码数
  lastPage: function() {
    var type = this.data.navType
    var page = this.data.page
    console.log(page)
    if (page == 0) {
      this.setData({
        page: 0
      })
      this.getTypeRequest(pagenum, type)
    } else {
      var pagenum = this.data.page -= 1
      this.setData({
        page: pagenum
      })
      this.getTypeRequest(pagenum, type)
    }
  },
  nextPage: function() {
    var pagenum = this.data.page += 1
    var type = this.data.navType
    this.setData({
      page: pagenum
    })
    this.getTypeRequest(pagenum, type)
  },
  MyshowLoading: function(pagenum,type) {
    wx.showLoading({
      title: '加载中',
    })
    this.getTypeRequest(pagenum,type)
    setTimeout(function() {
      wx.hideLoading()
    }, 1000)
  },
  /** 
   * 生命周期函数--监听页面加载 
   */
  onLoad: function(options) {
    // type=this.data.type 
    this.MyshowLoading(this.data.page,this.data.navType)
  },
  getTypeRequest: function(pagenum, type) {
    var url = "https://api.apiopen.top/getJoke"
    let that = this
    wx: wx.request({
      url: url,
      data: {
        "page": pagenum,
        "count": 5,
        "type": type
      },
      success: function(res) {
        that.setData({
          contentList: res.data.result
        })
        wx: wx.setStorageSync(key, data)
      },
      fail: function(res) {
        console.log(res.data.result.id)
      },
      complete: function(res) {},
    })
  },
  /** 
   * 生命周期函数--监听页面初次渲染完成 
   */
  onReady: function() {
    console.log("页面初次渲染完成")
  },
  /** 
   * 页面相关事件处理函数--监听用户下拉动作 
   */
  onPullDownRefresh: function() {
    console.log("下拉")
  },

  /** 
   * 页面上拉触底事件的处理函数 
   */
  onReachBottom: function() {
    console.log("页面上拉")
  },
  /** 
   * 页面上拉触底事件的处理函数 
   */
  onReachBottom: function() {
    console.log("页面上拉")
  }
})